<!DOCTYPE HTML>
<html lang="en">
<head>
<title>IfExist / IfNotExist - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The IfExist and IfNotExist statements check for the existence of a file or folder." />
<meta name="ahk:equiv-v2" content="commands/FileExist.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>If[Not]Exist</h1>

<p>Checks for the existence of a file or folder.</p>
<p class="warning"><strong>Deprecated:</strong> These commands are not recommended for use in new scripts. Use the <a href="FileExist.htm">FileExist</a> function instead.</p>

<pre class="Syntax">
<span class="func">IfExist</span>, FilePattern
<span class="func">IfNotExist</span>, FilePattern
</pre>
<h2>Parameters</h2>
<dl>

  <dt>FilePattern</dt>
  <dd><p>The path, filename, or file pattern to check. <em>FilePattern</em> is assumed to be in <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> if an absolute path isn't specified.</p></dd>

</dl>

<h2>Related</h2>
<p><a href="FileExist.htm">FileExist()</a>, <a href="Block.htm">Blocks</a>, <a href="Else.htm">Else</a>, <a href="LoopFile.htm">File-loops</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>IfExist, D:\
    MsgBox, The drive exists.
IfExist, D:\Docs\*.txt
    MsgBox, At least one .txt file exists.
IfNotExist, C:\Temp\FlagFile.txt
    MsgBox, The target file does not exist.</pre>
</div>

</body>
</html>
